import request from '@/utils/request'

export default {
  // 1.获取商品分类
  getCategories ({ type, pagenum, pagesize }) {
    return request({
      url: 'categories',
      method: 'get',
      params: {
        type,
        pagenum,
        pagesize
      }
    })
  },

  // 2.添加商品分类
  addCategory ({ cat_pid, cat_name, cat_level }) {
    return request({
      url: 'categories',
      method: 'post',
      data: {
        cat_pid,
        cat_name,
        cat_level
      }
    })
  },

  // 3.获取参数列表
  getParamList (id, selType) {
    return request({
      url: `categories/${id}/attributes`,
      method: 'get',
      params: {
        sel: selType
      }
    })
  },

  // 4.添加参数/属性
  addAttribute (id, attr_name, attr_sel) {
    return request({
      url: `categories/${id}/attributes`,
      method: 'post',
      data: {
        attr_name,
        attr_sel
      }
    })
  },

  // 5.根据id获取参数
  getAttributeById (id, attr_id, attr_sel) {
    return request({
      url: `categories/${id}/attributes/${attr_id}`,
      method: 'get',
      params: {
        attr_sel
      }
    })
  },

  // 6.提交编辑
  updateAttribute (id, attr_id, attr_name, attr_sel) {
    return request({
      url: `categories/${id}/attributes/${attr_id}`,
      method: 'put',
      data: {
        attr_name,
        attr_sel
      }
    })
  },

  // 7.删除参数
  deleteAttribute (id, attr_id) {
    return request({
      url: `categories/${id}/attributes/${attr_id}`,
      method: 'delete'
    })
  },

  // 8.添加参数
  addAttributes (id, attr_id, attr_name, attr_sel, attr_vals) {
    return request({
      url: `categories/${id}/attributes/${attr_id}`,
      method: 'put',
      data: {
        attr_name,
        attr_sel,
        attr_vals
      }
    })
  },

  // 9.获取商品列表
  getGoodsList ({ query, pagenum, pagesize }) {
    return request({
      url: 'goods',
      method: 'get',
      params: {
        query,
        pagenum,
        pagesize
      }
    })
  },

  // 10.添加商品
  addGoods (goods) {
    return request({
      url: 'goods',
      method: 'post',
      data: goods
    })
  }
}
